package com.woniu.springboot.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

//@SuppressWarnings("all")
@Entity
@Table(name = "student")
public class Student implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "sid")
	private Integer sid;
	
	@Column(name = "sname")
	private String sname;
	
	@Column(name = "age")
	private Integer age;
	
	//(fetch = FetchType.LAZY)
	@ManyToOne
	@Cascade(value = CascadeType.SAVE_UPDATE)
	@JoinColumn(name = "cid")
	private Clazz clazz;
	
	@Cascade(value=CascadeType.SAVE_UPDATE)
	@NotFound(action=NotFoundAction.IGNORE)
	//,fetch = FetchType.LAZY
	@ManyToMany(targetEntity=Teacher.class)
	@JoinTable(name="student_teacher",
		joinColumns=@JoinColumn(name="sid"),
		inverseJoinColumns = @JoinColumn(name="tid"))
	private List<Teacher> teachers;
	
	public Integer getSid() {
		return sid;
	}
	public void setSid(Integer sid) {
		this.sid = sid;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	public List<Teacher> getTeachers() {
		return teachers;
	}
	public void setTeacher(List<Teacher> teachers) {
		this.teachers = teachers;
	}
	public Clazz getClazz() {
		return clazz;
	}
	public void setClazz(Clazz clazz) {
		this.clazz = clazz;
	}
//	@Override
//	public String toString() {
//		return "Student [sid=" + sid + ", sname=" + sname + ", age=" + age
//				+ "]";
//	}
	@Override
	public String toString() {
		return "Student [sid=" + sid + ", sname=" + sname + ", age=" + age
				+ ", clazz=" + clazz + ", teachers=" + teachers + "]";
	}
	
	
	
}
